import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * @author Team Name: ByteCode
 * Team members: Kevin Conner, Vinesh Thakur, and James Yu
 * MancalaUndoPanel Class contains the information on players turn
 */
public class MancalaPlayerPanel extends JPanel{
   JTextField playerTurn = new JTextField();
   JButton undoButton = new JButton();
   MancalaDataModel mdm;
   
   /**
    * MancalaUndo Panel constructor sets up the button and view of the panel
    * @param mdm MancalaDataModel of the current data model
    */
   public MancalaPlayerPanel(final MancalaDataModel mdm)
   {
      super();
      this.mdm=mdm;
      playerTurn.setText(mdm.getPlayer()+"'s turn");
      playerTurn.setEditable(false);
     
      undoButton.addActionListener(new ActionListener() {

         public void actionPerformed(ActionEvent e) {
            mdm.undo();
         }
      });
      mdm.attach((new ChangeListener() {

         public void stateChanged(ChangeEvent e) {
            repaint();
         }
      }));
      this.add(playerTurn);
   }

   /**
    * paintComponent method draws the specific players turn and draw undo button
    * @param 
    */
   public void paintComponent(Graphics g){
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D)g;
      playerTurn.setText(mdm.getPlayer()+"'s turn.");
      undoButton.setText("Undos left: " + mdm.getUndofirst());

   }
}
